package com.jindy.module.salary.service.impl;

import java.util.List;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.salary.domain.Salary;
import com.jindy.module.salary.mapper.SalaryMapper;
import com.jindy.module.salary.service.ISalaryService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 薪资Service业务层处理
 *
 * @author ruoyi
 * @date 2022-09-28
 */
@Service
public class SalaryServiceImpl implements ISalaryService
{
    @Autowired
    private SalaryMapper salaryMapper;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询薪资
     *
     * @param id 薪资主键
     * @return 薪资
     */
    @Override
    public Salary selectSalaryById(Long id)
    {
        return salaryMapper.selectSalaryById(id);
    }

    /**
     * 查询薪资列表
     *
     * @param salary 薪资
     * @return 薪资
     */
    @Override
    public List<Salary> selectSalaryList(Salary salary)
    {
        return salaryMapper.selectSalaryList(salary);
    }

    /**
     * 新增薪资
     *
     * @param salary 薪资
     * @return 结果
     */
    @Override
    public int insertSalary(Salary salary)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        salary.setCreateId(sysUser.getUserId().toString());
        salary.setCreateBy(sysUser.getUserName());
        salary.setCreateTime(DateUtils.getNowDate());
        return salaryMapper.insertSalary(salary);
    }

    /**
     * 修改薪资
     *
     * @param salary 薪资
     * @return 结果
     */
    @Override
    public int updateSalary(Salary salary)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        salary.setUpdateBy(sysUser.getUserName());
        salary.setUpdateTime(DateUtils.getNowDate());
        return salaryMapper.updateSalary(salary);
    }

    /**
     * 批量删除薪资
     *
     * @param ids 需要删除的薪资主键
     * @return 结果
     */
    @Override
    public int deleteSalaryByIds(Long[] ids)
    {
        return salaryMapper.deleteSalaryByIds(ids);
    }

    /**
     * 删除薪资信息
     *
     * @param id 薪资主键
     * @return 结果
     */
    @Override
    public int deleteSalaryById(Long id)
    {
        return salaryMapper.deleteSalaryById(id);
    }
}
